import {onMounted, ref} from 'vue'
import {useRoute} from 'vue-router'
import {getCateGoryAPI} from '@/apis/category'
import { onBeforeRouteUpdate } from 'vue-router'



export function useCategory() {

const categoryData = ref({})
const router = useRoute()
const getCategory = async (id=router.params.id) => {
const res = await getCateGoryAPI(id)
  categoryData.value = res.result
}

onMounted(() => getCategory())

onBeforeRouteUpdate((to) => {
  console.log(to);
  getCategory(to.params.id)
})

return {
  categoryData
}
}
